package tool

import (
	"compress/gzip"
	"github.com/lishimeng/go-log"
	"io"
	"os"
)

func ReadGzip(file string, h func(reader io.Reader) error) (err error) {
	if h == nil {
		return
	}
	f, err := os.Open(file)
	if err != nil {
		log.Info(err)
		return
	}
	defer func() {
		_ = f.Close()
	}()
	reader, err := gzip.NewReader(f)
	if err != nil {
		log.Info(err)
		return
	}
	defer func() {
		_ = reader.Close()
	}()
	err = h(reader)
	return
}
